package cn.wolfcode.luowowo.website.web.controller;

import cn.wolfcode.luowowo.acticle.domain.FlightCity;
import cn.wolfcode.luowowo.acticle.domain.FlightScheduled;
import cn.wolfcode.luowowo.acticle.query.FlightScheduledQuery;
import cn.wolfcode.luowowo.acticle.service.IFlightCityService;
import cn.wolfcode.luowowo.acticle.service.IFlightScheduledService;
import cn.wolfcode.luowowo.common.exception.LogicException;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import cn.wolfcode.luowowo.common.util.DateUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.List;

@Controller
@RequestMapping("flight")

public class FlightController {

    @Reference
    private IFlightCityService flightCityService;
    @Reference
    private IFlightScheduledService flightScheduledService;

    @RequestMapping("")
    public String fight(Model model) {

        //hotFlights
        List<FlightCity> hotFlights =  flightCityService.listByStatus(1);
        model.addAttribute("hotFlights",hotFlights);

        //initialA
        List<FlightCity> initialA =  flightCityService.listByCode("A","B","C","D","E");
        model.addAttribute("initialA",initialA);

        //initialF
        List<FlightCity> initialF =  flightCityService.listByCode("F","G","H","J");
        model.addAttribute("initialF",initialF);
        //initialK
        List<FlightCity> initialK =  flightCityService.listByCode("K","L","M","N","P");
        model.addAttribute("initialK",initialK);

        //initialQ
        List<FlightCity> initialQ =  flightCityService.listByCode("Q","R","S","T","W");
        model.addAttribute("initialQ",initialQ);

        //initialX
        List<FlightCity> initialx =  flightCityService.listByCode("X","Y","Z");
        model.addAttribute("initialX",initialx);

        return "flight/index";
    }

    @RequestMapping("/search")
    public String flightSearch(Model model,@ModelAttribute("qo")FlightScheduledQuery qo){
        //List<FlightScheduled> list = flightScheduledService.listFlightScheduledForSearch(qo);

        PageInfo page = flightScheduledService.query(qo);

        model.addAttribute("pageInfo",page);

        return "flight/flightTpl";
    }

    @RequestMapping("ticket")
    public String ticket(Model model,int type,Long pid){
        FlightScheduled flightScheduled = flightScheduledService.getTicket(pid);
        model.addAttribute("flightScheduled",flightScheduled);
        model.addAttribute("type",type);
        if(type == 1){
            model.addAttribute("status",1);
        }
        return "flight/ticket";
    }
}
